﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;

namespace WebApp3
{
    public partial class Default1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.lblInfo.Text = System.DateTime.Now.ToString("yyyy年MM月dd日dddd HH时mm分ss秒");
            lblCheck.Text = "";
        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["Theme"] == null)
            {
                Page.Theme = "浅蓝色";
            }
            else if (Session["Theme"] == "浅蓝色")
            {
                Page.Theme = "浅蓝色";
            }
            else if (Session["Theme"] == "绿色")
            {
                Page.Theme = "绿色";
            }
            else if (Session["Theme"] == "黄色")
            {
                Page.Theme = "黄色";
            }
            else
            {
                Page.Theme = "红色";
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            
            
           
            string strCn = "server=pc.hstc.cn;database=dhd2014112111;uid=2014112111;pwd=19950511";
            SqlConnection cn = new SqlConnection(strCn);
            if (this.rbUser.Checked == true)
            {
                try
                {
                    string UserName = this.txtUserName.Text.ToString();
                    string UserPassword = this.txtPassword.Text.ToString();
                    cn.Open();
                    string strSql = "SELECT   Name, PassWord , Sex , Createtime , Picture, QqEmail, gxqm  FROM      Register  WHERE   (Name = N'" + txtUserName.Text + "') AND (PassWord = N'" + txtPassword.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        this.txtUserName.Text = dr["Name"].ToString();
                        this.txtPassword.Text = dr["PassWord"].ToString();
                        string checkcode = Session["CheckCode"].ToString();
                        if (this.TextBox1.Text == checkcode)
                        {
                            Session["chuandiname"] = dr["Name"].ToString();
                            Session["chuandipassword"] = dr["PassWord"].ToString();
                            Session["chuandisex"] = dr["Sex"].ToString();
                            Session["chuandicreatetime"] = dr["Createtime"].ToString();
                            Session["chuandiimageurl"] = "~\\headImage\\" + dr["Picture"].ToString() + ".gif";
                            Session["chuandiqqemail"] = dr["QqEmail"].ToString();
                            Session["chuandigxqm"] = dr["gxqm"].ToString();
                            Response.Redirect("frmUserf.aspx");
                        }
                        else
                        {
<<<<<<< HEAD
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!李四改的')", true); 
=======
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!张三改的')", true); 
>>>>>>> ba177134372df475c613387235009a1a60205117
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='default.aspx';</script>");
                    }
                }
                catch (Exception ex)
                {
                    this.lblInfo.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                }
            }
            else if (this.rbAdmin.Checked == true)
            {
                try
                {
                    string UserName = this.txtUserName.Text.ToString();
                    string UserPassword = this.txtPassword.Text.ToString();
                    cn.Open();
                    string strSql = "SELECT   UserName, Password, Sex, QqEmail, Picture   FROM      UserInfo  WHERE   (UserName = N'" + txtUserName.Text + "') AND (Password = N'" + txtPassword.Text + "')";
                    SqlCommand cmd = new SqlCommand(strSql, cn);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        this.txtUserName.Text = dr["UserName"].ToString();
                        this.txtPassword.Text = dr["Password"].ToString();
                        string checkcode = Session["CheckCode"].ToString();
                        if (this.TextBox1.Text == checkcode)
                        {
                            Session["chuandiname"] = dr["UserName"].ToString();
                            Session["chuandipassword"] = dr["Password"].ToString();
                            Session["chuandisex"] = dr["Sex"].ToString();
                            Session["chuandiimageurl"] = "~\\headImage\\" + dr["Picture"].ToString() + ".gif";
                            Session["chuandiqqemail"] = dr["QqEmail"].ToString();
                            Response.Redirect("frmAdminSy.aspx");
                        }
                        else
                        {
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('验证码输入错误!')", true);
                        }

                        

                        
                    }
                    else
                    {
                        Response.Write("<script>alert('您填写的登录信息有误，请重新填写。');location.href='default.aspx';</script>");
                    }
                }
                catch (Exception ex)
                {
                    this.lblInfo.Text = ex.Message;
                }
                finally
                {
                    cn.Close();
                }
            }
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            txtUserName.Text = "";
            txtPassword.Text = "";
            TextBox1.Text = "";
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            string strCn = "server=pc.hstc.cn;database=dhd2014112111;uid=2014112111;pwd=19950511";
            SqlConnection cn = new SqlConnection(strCn);
            Response.Redirect("frmRegister.aspx");
        }
    }
}